<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>赛诺菲_西南区 销量统计系统</title>
		<%@ include file="../inc/fileHead.jsp"%>
	<body  class="easyui-layout"> 
	<div data-options="region:'center'">
		<table id="dg" title="客户管理" class="easyui-datagrid"
			url="CustomerAction_findAllCustomer" toolbar="#toolbar"
			pagination="true" rownumbers="true" fitColumns="true"
			singleSelect="true">
			<thead>
				<tr>
					<th field="customername" width="50">
						客户名称
					</th>
					<th field="customerlevel" width="50">
						客户级别
					</th>
					<th field="customerstatus" width="50">
						客户状态
					</th>
				</tr>
			</thead>
		</table>
		<div id="toolbar">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-add" plain="true" onclick="newUser()">添加客户</a>
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-edit" plain="true" onclick="editUser()">修改客户</a>
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-remove" plain="true" onclick="destroyUser()">删除客户</a>
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-search" plain="true" onclick="searchForUser()">查询客户</a>
		</div>
		<div id="searchdlg" class="easyui-dialog"
				style="width: 400px; height: 280px; padding: 10px 20px"
				closed="true" buttons="#dlg-buttons2">
				<div class="ftitle">
					查询条件
				</div>
				<div class="fitem">
					<label>
						客户名称
					</label>
					<input id="q_customername" name="q_customername" class="easyui-validatebox" />
				</div>
				<div class="fitem">
					<label>
						客户级别
					</label>
					<input id="q_customerlevel" name="q_customerlevel" class="easyui-combobox"
						data-options="  
                    url:'BaseAction_selectGetCustomerLevel',  
                    valueField:'name',  
                    textField:'name',  
                    panelHeight:'auto'  
            ">
				</div>
			</div>
		<div id="dlg" class="easyui-dialog"
			style="width: 400px; height: 280px; padding: 10px 20px" closed="true"
			buttons="#dlg-buttons">
			<div class="ftitle">
				客户信息
			</div>
			<form id="fm" method="post" novalidate>
				<div class="fitem">
					<label>
						客户名称
					</label>
					<input name="customername" class="easyui-validatebox"
						style="width: 200px" required="true">
				</div>
				<div class="fitem">
					<label>
						客户级别
					</label>
					<input class="easyui-combobox" name="customerlevel" required="true"
						style="width: 200px"
						data-options="  
                    url:'BaseAction_selectGetCustomerLevel',  
                    valueField:'name',  
                    textField:'name',  
                    panelHeight:'auto'  
            ">
				</div>
				<div class="fitem">
					<label>
						客户状态
					</label>
					<select name="customerstatus" class="easyui-combobox"
						required="true" style="width: 200px">
						<option value="0">无效</option>
						<option value="1">有效</option>
					</select>
				</div>
			</form>
		</div>
		<div id="dlg-buttons">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-ok" onclick="saveUser()">保存</a>
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
		</div>
		<div id="dlg-buttons2">
				<a href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-ok" onclick="searchUser()">查询</a>
				<a href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-cancel"
					onclick="javascript:$('#dlg').dialog('close')">取消</a>
			</div>
		<script type="text/javascript">
		var url;
		function newUser() {
			$('#dlg').dialog('open').dialog('setTitle', '添加客户');
			$('#fm').form('clear');
			url = 'CustomerAction_addCustomer';
		}
		function editUser() {
			var row = $('#dg').datagrid('getSelected');
			if (row) {
				$('#dlg').dialog('open').dialog('setTitle', '修改客户');
				$('#fm').form('load', row);
				url = 'CustomerAction_updateCustomer?id=' + row.id;
			}
		}
		function saveUser() {
			$('#fm').form('submit', {
				url : url,
				onSubmit : function() {
					if($(this).form('validate')){
                    		return true;
                    }else{
                    		$.messager.alert('提示','请填写完整资料!'); 
                        	return false;
                    }  
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.errorMsg) {
						$.messager.alert('错误',result.errorMsg); 
					} else {
						$('#dlg').dialog('close'); // close the dialog  
						$('#dg').datagrid('reload'); // reload the user data  
					}
				}
			});
		}
		function destroyUser() {
			var row = $('#dg').datagrid('getSelected');
			if (row) {
				$.messager.confirm('Confirm',
						'确定要删除这个客户?',
						function(r) {
							if (r) {
								$.post('CustomerAction_deleteCustomer', {
									id : row.id
								}, function(result) {
									if (result.success) {
										$('#dg').datagrid('reload'); // reload the user data  
									} else {
										$.messager.alert('错误',result.errorMsg); 
									}
								}, 'json');
							}
						});
			}
		}
		
		function searchForUser(){
            	$('#searchdlg').dialog('open').dialog('setTitle','查询客户');  
        }
        function searchUser(){  
                 $('#searchdlg').dialog('close');      // close the dialog
                 $('#dg').datagrid({
                 url:'CustomerAction_findByParam',  
				 queryParams: {
					q_customername: $('#q_customername').val(),
					q_customerlevel: $('#q_customerlevel').combobox('getValue')
				}
				});
            }  
	</script>
		<style type="text/css">
#fm {
	margin: 0;
	padding: 10px 30px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 5px;
}

.fitem label {
	display: inline-block;
	width: 80px;
}
</style>
</div>
	</body>
</html>